package com.qzxy.premiumhotelsystem.controller.guest;

import com.qzxy.premiumhotelsystem.domain.dto.PayVipOrderDTO;
import com.qzxy.premiumhotelsystem.domain.dto.VipRenewDTO;
import com.qzxy.premiumhotelsystem.domain.entity.VipTypes;
import com.qzxy.premiumhotelsystem.domain.vo.VipOrderVO;
import com.qzxy.premiumhotelsystem.domain.vo.VipVO;

import com.qzxy.premiumhotelsystem.common.result.Result;
import com.qzxy.premiumhotelsystem.service.VipOrdersService;
import com.qzxy.premiumhotelsystem.service.VipService;
import com.qzxy.premiumhotelsystem.service.VipTypesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * ClassName: VipController
 * Package: com.qzxy.premiumhotelsystem.controller
 * Description:
 *
 * @Author Qwh
 * @Create 2024/9/12 16:04
 * @Version 1.0
 */

@RestController("userVipController")
@RequestMapping("/user/vip")
@Tag(name = "用户端vip会员相关接口")
@Slf4j
public class VipController {



    @Resource
    private VipTypesService vipTypesService;
    @Resource
    private VipOrdersService vipOrdersService;
    @Resource
    private VipService vipService;


    @Operation(summary = "查询所有可用的会员类型，供用户购买时参考。",description = "这里说明，用户一旦成功购买会员，不支持取消（退款）")
    @GetMapping("/types")
    public Result getVipTypes() {
        // 用户查询所有的会员类型
        List<VipTypes> list = vipTypesService.list();
        return Result.ok(list);
    }


    @Operation(summary = "用户点击购买会员，生成一条“未支付”的订单",description = "用户可购买不同类型的会员，拥有多个会员用户可选择使用哪个折扣")
    @PostMapping("/purchase")
    public Result purchaseVip(@RequestParam Integer vipTypeId ) {
        // 生成未支付的订单
        Result result = vipOrdersService.createOrder(vipTypeId);
        return result;
    }


    @Operation(summary = "支付会员订单")
    @PostMapping("/pay")
    public Result payByBalance(@ParameterObject @Validated PayVipOrderDTO payVipOrderDTO){

        Result result = vipOrdersService.payVipOrder(payVipOrderDTO);
        return result;
    }

    @Operation(summary = "查看已购买的所有VIP会员信息",description = "这里包括过期还未删除记录的")
    @GetMapping("/info")
    public Result getVipInfo() {
        // 查询用户已经激活的 VIP 会员信息
        List<VipVO> vipList = vipService.getActiveVip();
        return Result.ok(vipList);
    }


    @Operation(summary = "查询会员订单历史")
    @GetMapping("/orders")
    public Result getVipOrders() {

        List<VipOrderVO> orders = vipOrdersService.getOrders();
        return Result.ok(orders);
    }

    @Operation(summary = "用户续费VIP会员")
    @PostMapping("/renew")
    public Result renewVip(@ParameterObject @Validated VipRenewDTO vipRenewDTO) {
        Result result = vipService.renewVip(vipRenewDTO);
        return result;
    }

    /**
     * 根据vipid获取vip名字
     * @param vipTypeId
     * @return
     */
    @Operation(summary = "根据vipid获取vip名字")
    @GetMapping("/vipId")
    public Result getByVipTypeIdString(@RequestParam String vipTypeId) {
        return Result.ok(vipTypesService.getByVipTypeIdString(vipTypeId));
    }

    /**
     * 会员管理所需
     * @return
     */
    @Operation(summary = "获取所有会员信息")
    @GetMapping("/all")
    public Result getAllVip() {
        return Result.ok(vipService.allVip());
    }

}